package view.panel.friend
{
	import control.panel.FriendPanelControl;
	import control.panel.IPanelControl;
	
	import events.TabEvent;
	
	import flash.events.MouseEvent;
	
	import model.room.FriendData;
	
	import view.components.ImgButton;
	import view.components.list.TileList;
	import view.components.tab.Tab;
	import view.components.tab.TabBar;
	import view.panel.AbsPanel;
	
	public class FriendPanel extends AbsPanel
	{
		private var tab:Tab;
		private var playFriendlist:TileList;
		private var selfFriendList:TileList;
		private var deleteBut:ImgButton;
		
		public function FriendPanel(panelControl:IPanelControl)
		{
			super(panelControl);
			
			defaultX = 6;
			defaultY = 105;
			resetBg(215,282);
			dropShadow();
			initCloseBut();
			resetCloseBut();
			initTweenPanelOpen();
			
			initTab();
			initList();
			initBut();
			
		}
		
		private function initBut():void
		{
			deleteBut = new ImgButton(86,253,0,onBut,45,24,"butBg",null,"删除");
			addChild(deleteBut);
			deleteBut.visible = false;
		}
		
		private function onBut(event:MouseEvent):void
		{
			(panelControl as FriendPanelControl).deleteFriend();
		}
	
		private function initList():void
		{
			selfFriendList = new TileList(185,210,new ListFriendItem(false));
			selfFriendList.x = 15;
			selfFriendList.y = 40;
			selfFriendList.drawBg();
			addChild(selfFriendList);
			
			
			playFriendlist = new TileList(185,210,new ListFriendItem(),true);
			playFriendlist.x = 15;
			playFriendlist.y = 40;
			playFriendlist.drawBg();
			addChild(playFriendlist);
			playFriendlist.visible = false;
			
		}
		
		
		public function update(datas:Array):void
		{
			selfFriendList.removeAll();
			playFriendlist.removeAll();
			for each (var data:FriendData in datas)
			{
				if (data.type == 0)
				{
					selfFriendList.addItem(data);
				}
				else
				{
					playFriendlist.addItem(data);
				}
			
			}
		}
		
		private function initTab():void
		{
			tab = new Tab();
			tab.addTabBar(new TabBar(0,"好 友",60),true);
			tab.addTabBar(new TabBar(0,"牌 友",60));
			tab.y = 10;
			tab.x = 24;
			addChild(tab);
			
			tab.addEventListener(TabEvent.TABBAR_CLICK,onTabClick);
		}
		
		private function onTabClick(event:TabEvent):void
		{
			switch(event.index)
			{
				case 0:
					deleteBut.visible = false;
					playFriendlist.visible = false;
					selfFriendList.visible = true;
					break;
				case 1:
					deleteBut.visible = true;
					playFriendlist.visible = true;
					selfFriendList.visible = false;
					break;
			}
		}
	}
}